//父类构造函数
function SuperType(name){
    this.name = name;
    this.colors = ['red','green','blue'];
}
//父类构造函数原型定义sayName方法
SuperType.prototype.sayName = function(){
    console.log(this.name)
}
//子类构造函数
function SubType(name,age){
    //盗用父类构造函数
    SuperType.call(this,name);
    //定义子类的属性
    this.age = age;
}
//原型继承--原型链继承 子类的原型重写为父类的实例
SubType.prototype = new SuperType();
//重写子类的原型后，原型定义sayAge方法
SubType.prototype.sayAge = function(){
    console.log(this.age);
}
let instance1 = new SubType('silly',26);
instance1.colors.push('black');
console.log(instance1.name);//silly
console.log(instance1.age);//26
console.log(instance1.colors);//[ 'red', 'green', 'blue', 'black' ]
instance1.sayName();//silly
instance1.sayAge();//26
console.log('---------------------------------------------------')
let instance2 = new SubType('smith',30);
console.log(instance2.name);//smith
console.log(instance2.age);//30
console.log(instance2.colors);//[ 'red', 'green', 'blue' ]
instance2.sayName();//smith
instance2.sayAge();//30

console.log(instance1 instanceof SubType);//true
console.log(instance1 instanceof SuperType);//true
console.log(SubType.prototype.isPrototypeOf(instance2));//true
console.log(SuperType.prototype.isPrototypeOf(instance2));//true